<template>
	<view>
		<slot></slot>
	</view>
</template>
<script>
	import permision from "@/js_sdk/wa-permission/permission.js"
	export default {
		name: "permision_name",
		data() {
			return {}

		},
		methods: {
			async openPermision(item, pageType) {
				// #ifdef APP
				let res = await this.judgeIosPermission()
				// #endif
				// #ifdef H5
				let res = 2
				// #endif

				return new Promise((resolve, reject) => {					
					if (res != 2) {
						uni.showModal({
							title: '提示',
							content: "您禁止了媒体与文件权限，如需使用请开启权限设置",
							success: function(res) {
								if (res.confirm) {
									permision.gotoAppPermissionSetting()
								}
							}
						});
					} else {
						resolve(true)
					}
				})


			},
			// //查询 权限
			async judgeIosPermission() {
				let statusNum = 0
				//权限
				let arr = ["android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE"]
				const getPermission = (permisionID) => {
					return permision.requestAndroidPermission(permisionID)
				}
				for (let item in arr) {
					console.log("item", arr[item])
					let res = await getPermission(arr[item])
					console.log("res", res)
					if (res == 1) {
						statusNum++
					}
				}
				return statusNum
			},
			async requestAndroidPermission(permisionID) {
				var result = await permision.requestAndroidPermission(permisionID)
				var strStatus
				if (result == 1) {
					strStatus = "已获得授权"
					switch (permisionID) {
						case "android.permission.CAMERA":
							this.CAMERA = true
							uni.setStorageSync("CAMERA", true)
							break;
						case "android.permission.READ_EXTERNAL_STORAGE":
							this.READ_EXTERNAL_STORAGE = true
							uni.setStorageSync("READ_EXTERNAL_STORAGE", true)

							break;
						case "android.permission.WRITE_EXTERNAL_STORAGE":
							this.WRITE_EXTERNAL_STORAGE = true
							uni.setStorageSync("WRITE_EXTERNAL_STORAGE", true)
							break;

						case "android.permission.ACCESS_FINE_LOCATION":
							this.ACCESS_FINE_LOCATION = true
							uni.setStorageSync("ACCESS_FINE_LOCATION", true)
							break;
					}
				} else if (result == 0) {
					strStatus = "未获得授权"
				} else {
					strStatus = "被永久拒绝权限"
				}
			},


		}

	}
</script>

<style scoped lang="scss"></style>
